<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for utils/excel.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">All files</a> / <a href="index.html">utils</a> excel.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/118</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/59</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/11</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/109</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >import { saveAs } from 'file-saver'</span>
<span class="cstat-no" title="statement not covered" >import XLSX, { WorkBook, WorkSheet } from 'xlsx'</span>
&nbsp;
interface ICell {
  v: Date | number | boolean | string
  t: string
  z: string
}
&nbsp;
<span class="fstat-no" title="function not covered" >class Workbook implements WorkBook {</span>
<span class="cstat-no" title="statement not covered" >  SheetNames: string[] = []</span>
<span class="cstat-no" title="statement not covered" >  Sheets: { [sheet: string]: WorkSheet } = {}</span>
}
&nbsp;
const generateArray = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >table: HTMLElement) =&gt; {</span></span>
  const out = <span class="cstat-no" title="statement not covered" >[]</span>
  const rows = <span class="cstat-no" title="statement not covered" >table.querySelectorAll('tr')</span>
  const ranges = <span class="cstat-no" title="statement not covered" >[]</span>
<span class="cstat-no" title="statement not covered" >  for (let R = 0; R &lt; rows.length; ++R) {</span>
    const outRow = <span class="cstat-no" title="statement not covered" >[]</span>
    const row = <span class="cstat-no" title="statement not covered" >rows[R]</span>
    const columns = <span class="cstat-no" title="statement not covered" >row.querySelectorAll('td')</span>
<span class="cstat-no" title="statement not covered" >    for (let C = 0; C &lt; columns.length; ++C) {</span>
      const cell = <span class="cstat-no" title="statement not covered" >columns[C]</span>
      const colspanStr = <span class="cstat-no" title="statement not covered" >cell.getAttribute('colspan')</span>
      const rowspanStr = <span class="cstat-no" title="statement not covered" >cell.getAttribute('rowspan')</span>
      let colspan
      let rowspan
<span class="cstat-no" title="statement not covered" >      if (colspanStr) {</span>
<span class="cstat-no" title="statement not covered" >        colspan = parseInt(colspanStr)</span>
      }
<span class="cstat-no" title="statement not covered" >      if (rowspanStr) {</span>
<span class="cstat-no" title="statement not covered" >        rowspan = parseInt(rowspanStr)</span>
      }
      let cellValue = <span class="cstat-no" title="statement not covered" >cell.innerText</span>
      // Skip ranges
<span class="cstat-no" title="statement not covered" >      ranges.forEach(<span class="fstat-no" title="function not covered" >function(</span>range) {</span>
<span class="cstat-no" title="statement not covered" >        if (R &gt;= range.s.r &amp;&amp; R &lt;= range.e.r &amp;&amp; outRow.length &gt;= range.s.c &amp;&amp; outRow.length &lt;= range.e.c) {</span>
<span class="cstat-no" title="statement not covered" >          for (let i = 0; i &lt;= range.e.c - range.s.c; ++i) <span class="cstat-no" title="statement not covered" >o</span>utRow.push(null)</span>
        }
      })
      // Handle Row Span
<span class="cstat-no" title="statement not covered" >      if (rowspan || colspan) {</span>
<span class="cstat-no" title="statement not covered" >        rowspan = rowspan || 1</span>
<span class="cstat-no" title="statement not covered" >        colspan = colspan || 1</span>
<span class="cstat-no" title="statement not covered" >        ranges.push({</span>
          s: {
            r: R,
            c: outRow.length
          },
          e: {
            r: R + rowspan - 1,
            c: outRow.length + colspan - 1
          }
        })
      }
      // Handle Value
<span class="cstat-no" title="statement not covered" >      outRow.push(cellValue !== '' ? cellValue : null)</span>
      // Handle Colspan
<span class="cstat-no" title="statement not covered" >      if (colspan) {</span>
<span class="cstat-no" title="statement not covered" >        for (let k = 0; k &lt; colspan - 1; ++k) {</span>
<span class="cstat-no" title="statement not covered" >          outRow.push(null)</span>
        }
      }
    }
<span class="cstat-no" title="statement not covered" >    out.push(outRow)</span>
  }
<span class="cstat-no" title="statement not covered" >  return [out, ranges]</span>
}
&nbsp;
const datenum = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >date: Date) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >  return (+date - +new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000)</span>
}
&nbsp;
const sheetFromDataArray = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >data: any) =&gt; {</span></span>
  const ws: { [key: string]: any } = <span class="cstat-no" title="statement not covered" >{}</span>
  const range = <span class="cstat-no" title="statement not covered" >{</span>
    s: {
      c: 10000000,
      r: 10000000
    },
    e: {
      c: 0,
      r: 0
    }
  }
<span class="cstat-no" title="statement not covered" >  for (let R = 0; R !== data.length; ++R) {</span>
<span class="cstat-no" title="statement not covered" >    for (let C = 0; C !== data[R].length; ++C) {</span>
<span class="cstat-no" title="statement not covered" >      if (range.s.r &gt; R) <span class="cstat-no" title="statement not covered" >r</span>ange.s.r = R</span>
<span class="cstat-no" title="statement not covered" >      if (range.s.c &gt; C) <span class="cstat-no" title="statement not covered" >r</span>ange.s.c = C</span>
<span class="cstat-no" title="statement not covered" >      if (range.e.r &lt; R) <span class="cstat-no" title="statement not covered" >r</span>ange.e.r = R</span>
<span class="cstat-no" title="statement not covered" >      if (range.e.c &lt; C) <span class="cstat-no" title="statement not covered" >r</span>ange.e.c = C</span>
      const cell: ICell = <span class="cstat-no" title="statement not covered" >{</span>
        v: data[R][C],
        t: '',
        z: ''
      }
<span class="cstat-no" title="statement not covered" >      if (cell.v == null) <span class="cstat-no" title="statement not covered" >c</span>ontinue</span>
      const cellRef = <span class="cstat-no" title="statement not covered" >XLSX.utils.encode_cell({</span>
        c: C,
        r: R
      })
<span class="cstat-no" title="statement not covered" >      if (typeof cell.v === 'number') <span class="cstat-no" title="statement not covered" >cell.t = 'n'</span></span>
      else <span class="cstat-no" title="statement not covered" >if (typeof cell.v === 'boolean') <span class="cstat-no" title="statement not covered" >cell.t = 'b'</span></span>
      else <span class="cstat-no" title="statement not covered" >if (cell.v instanceof Date) {</span>
<span class="cstat-no" title="statement not covered" >        cell.t = 'n'</span>
<span class="cstat-no" title="statement not covered" >        cell.z = XLSX.SSF.get_table()[14]</span>
<span class="cstat-no" title="statement not covered" >        cell.v = datenum(cell.v)</span>
      } else <span class="cstat-no" title="statement not covered" >cell.t = 's'</span>
<span class="cstat-no" title="statement not covered" >      ws[cellRef] = cell</span>
    }
  }
<span class="cstat-no" title="statement not covered" >  if (range.s.c &lt; 10000000) {</span>
<span class="cstat-no" title="statement not covered" >    ws['!ref'] = XLSX.utils.encode_range(range)</span>
  }
<span class="cstat-no" title="statement not covered" >  return ws</span>
}
&nbsp;
const s2ab = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >s: string) =&gt; {</span></span>
  const buf = <span class="cstat-no" title="statement not covered" >new ArrayBuffer(s.length)</span>
  const view = <span class="cstat-no" title="statement not covered" >new Uint8Array(buf)</span>
<span class="cstat-no" title="statement not covered" >  for (let i = 0; i !== s.length; ++i) {</span>
<span class="cstat-no" title="statement not covered" >    view[i] = s.charCodeAt(i) &amp; 0xFF</span>
  }
<span class="cstat-no" title="statement not covered" >  return buf</span>
}
&nbsp;
export const exportTable2Excel = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >id: string) =&gt; {</span></span>
  const theTable = <span class="cstat-no" title="statement not covered" >document.getElementById(id)</span>
<span class="cstat-no" title="statement not covered" >  if (theTable) {</span>
    const oo = <span class="cstat-no" title="statement not covered" >generateArray(theTable)</span>
    const ranges = <span class="cstat-no" title="statement not covered" >oo[1]</span>
&nbsp;
    /* original data */
    const data = <span class="cstat-no" title="statement not covered" >oo[0]</span>
    const wsName: string = <span class="cstat-no" title="statement not covered" >'SheetJS'</span>
&nbsp;
    const wb = <span class="cstat-no" title="statement not covered" >new Workbook()</span>
    const ws = <span class="cstat-no" title="statement not covered" >sheetFromDataArray(data)</span>
&nbsp;
    /* add ranges to worksheet */
    // ws['!cols'] = ['apple', 'banan']
<span class="cstat-no" title="statement not covered" >    ws['!merges'] = ranges</span>
&nbsp;
    /* add worksheet to workbook */
<span class="cstat-no" title="statement not covered" >    wb.SheetNames.push(wsName)</span>
<span class="cstat-no" title="statement not covered" >    wb.Sheets[wsName] = ws</span>
&nbsp;
    const wbout = <span class="cstat-no" title="statement not covered" >XLSX.write(wb, {</span>
      bookType: 'xlsx',
      bookSST: false,
      type: 'binary'
    })
&nbsp;
<span class="cstat-no" title="statement not covered" >    saveAs(new Blob([s2ab(wbout)], {</span>
      type: 'application/octet-stream'
    }), 'test.xlsx')
  }
}
&nbsp;
export const exportJson2Excel = <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >(h</span>eader: string[], data: any, filename: string = <span class="branch-0 cbranch-no" title="branch not covered" >'excel-list', multiHeader: string[][] = <span class="branch-0 cbranch-no" title="branch not covered" >[], merges:any[] = <span class="branch-0 cbranch-no" title="branch not covered" >[], autoWidth: boolean = <span class="branch-0 cbranch-no" title="branch not covered" >true, bookType: string = <span class="branch-0 cbranch-no" title="branch not covered" >'xlsx') =&gt; {</span></span></span></span></span></span>
<span class="cstat-no" title="statement not covered" >  data = [...data]</span>
<span class="cstat-no" title="statement not covered" >  data.unshift(header)</span>
<span class="cstat-no" title="statement not covered" >  for (let i = multiHeader.length - 1; i &gt; -1; i--) {</span>
<span class="cstat-no" title="statement not covered" >    data.unshift(multiHeader[i])</span>
  }
&nbsp;
  const wsName = <span class="cstat-no" title="statement not covered" >'SheetJS'</span>
  const wb = <span class="cstat-no" title="statement not covered" >new Workbook()</span>
  const ws = <span class="cstat-no" title="statement not covered" >sheetFromDataArray(data)</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >  if (merges.length &gt; 0) {</span>
<span class="cstat-no" title="statement not covered" >    if (!ws['!merges']) {</span>
<span class="cstat-no" title="statement not covered" >      ws['!merges'] = []</span>
    }
<span class="cstat-no" title="statement not covered" >    merges.forEach(<span class="fstat-no" title="function not covered" >item</span> =&gt; {</span>
<span class="cstat-no" title="statement not covered" >      ws['!merges'].push(XLSX.utils.decode_range(item))</span>
    })
  }
&nbsp;
<span class="cstat-no" title="statement not covered" >  if (autoWidth) {</span>
    // 设置worksheet每列的最大宽度
    const colWidth = <span class="cstat-no" title="statement not covered" >data.map((<span class="fstat-no" title="function not covered" >row: any) =&gt; <span class="cstat-no" title="statement not covered" >row.map((<span class="fstat-no" title="function not covered" >val: any) =&gt; {</span></span></span></span>
      // 先判断是否为 null/undefined
<span class="cstat-no" title="statement not covered" >      if (val == null) {</span>
<span class="cstat-no" title="statement not covered" >        return {</span>
          'wch': 10
        }
      // 再判断是否为中文
      } else <span class="cstat-no" title="statement not covered" >if (val.toString().charCodeAt(0) &gt; 255) {</span>
<span class="cstat-no" title="statement not covered" >        return {</span>
          'wch': val.toString().length * 2
        }
      } else {
<span class="cstat-no" title="statement not covered" >        return {</span>
          'wch': val.toString().length
        }
      }
    }))
    // 以第一行为初始值
    let result = <span class="cstat-no" title="statement not covered" >colWidth[0]</span>
<span class="cstat-no" title="statement not covered" >    for (let i = 1; i &lt; colWidth.length; i++) {</span>
<span class="cstat-no" title="statement not covered" >      for (let j = 0; j &lt; colWidth[i].length; j++) {</span>
<span class="cstat-no" title="statement not covered" >        if (result[j]['wch'] &lt; colWidth[i][j]['wch']) {</span>
<span class="cstat-no" title="statement not covered" >          result[j]['wch'] = colWidth[i][j]['wch']</span>
        }
      }
    }
<span class="cstat-no" title="statement not covered" >    ws['!cols'] = result</span>
  }
&nbsp;
  // Add worksheet to workbook
<span class="cstat-no" title="statement not covered" >  wb.SheetNames.push(wsName)</span>
<span class="cstat-no" title="statement not covered" >  wb.Sheets[wsName] = ws</span>
&nbsp;
  const wbout = <span class="cstat-no" title="statement not covered" >XLSX.write(wb, {</span>
    bookType: bookType as any,
    bookSST: false,
    type: 'binary'
  })
&nbsp;
<span class="cstat-no" title="statement not covered" >  saveAs(new Blob([s2ab(wbout)], {</span>
    type: 'application/octet-stream'
  }), `${filename}.${bookType}`)
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Aug 05 2019 17:01:25 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
